<template>
  <div class="cardItem">
    <el-card class="cardItem-card">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/employees' }">
          员工管理</el-breadcrumb-item
        >
        <el-breadcrumb-item>离职</el-breadcrumb-item>
      </el-breadcrumb>
      <hr />
      <!--  -->
      <p class="top">离职</p>
      <Header ref="header"></Header>
      <hr>
      <el-form label-width="240px" :model="form" :rules="rules" ref="form">
        <el-form-item label="离职类型" prop="typeOfTurnover">
          <el-select v-model="form.typeOfTurnover">
            <el-option
              v-for="item in EmployeeEnum.leaveType"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="离职时间" prop="resignationTime">
          <el-date-picker
            type="date"
            value-format="yyyy-MM-DD"
            v-model="form.resignationTime"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="申请离职原因" prop="reasonsForLeaving">
          <el-input type="textarea" v-model="form.reasonsForLeaving"></el-input>
        </el-form-item>
        <el-form-item label="补偿金">
          <el-input placeholder="100" v-model="form.compensation"></el-input> ￥
        </el-form-item>
        <el-form-item label="代理织金">
          <el-input placeholder="100" v-model="form.notifications"></el-input> ￥
        </el-form-item>
        <el-form-item label="社保减员月" prop="socialSecurityReductionMonth">
          <el-select v-model="form.socialSecurityReductionMonth">
            <el-option
              v-for="item in EmployeeEnum.attritionMonth"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公积金减员月" prop="providentFundReductionMonth">
          <el-select v-model="form.providentFundReductionMonth">
            <el-option
              v-for="item in EmployeeEnum.attritionMonth"
              :key="item.id"
              :label="item.value"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="剩余年限">
          <el-input :disabled="true" placeholder="0"></el-input>
        </el-form-item>
        <el-form-item label="剩余调休">
          <el-input :disabled="true" placeholder="0"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button>返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { employeesLeaveGet, employeesLeavePut } from '@/api/employees'
import EmployeeEnum from '@/assets/constant/employees'
import Header from './components/header'
export default {
  name: 'cardItem',
  components: {
    Header
  },
  data () {
    return {
      EmployeeEnum,
      id: this.$route.params.id,
      form: {
        compensation: '', //	string	非必须		补偿金
        createTime: '', //	string	非必须		创建时间
        notifications: '', //	string	非必须		代通知金
        picture: '', //	string	非必须		图片
        providentFundReductionMonth: '', //	string	非必须		公积金减员月
        reasonsForLeaving: '', //	string	非必须		申请离职原因
        resignationTime: '', //	string	非必须		离职时间
        socialSecurityReductionMonth: '', //	string	非必须		社保减员月
        typeOfTurnover: '', //	string	非必须		离职类型
        userId: '' //	string	非必须		员工Id
      },
      rules: {
        providentFundReductionMonth: [
          { required: true, message: '必填', trigger: 'change' }
        ], //	string	非必须		公积金减员月
        reasonsForLeaving: [
          { required: true, message: '必填', trigger: 'change' }
        ], //	string	非必须		申请离职原因
        resignationTime: [
          { required: true, message: '必填', trigger: 'change' }
        ], //	string	非必须		离职时间
        socialSecurityReductionMonth: [
          { required: true, message: '必填', trigger: 'change' }
        ], //	string	非必须		社保减员月
        typeOfTurnover: [{ required: true, message: '必填', trigger: 'change' }] //	string	非必须		离职类型
      }
    }
  },
  created () {
    this.getData()
    console.log(this.id)
  },
  methods: {
    async getData () {
      const res = await employeesLeaveGet()
      console.log('离职信息', res)
    },
    submit () {
      this.$refs.form.validate(async result => {
        if (result) {
          this.picture=this.$refs.header.userInfo.staffPhoto
          // this.createTime=new Date()
          this.userId=this.id
       const res=   await employeesLeavePut(this.id)
          this.$message.success('提交成功')
          console.log(result,res)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.cardItem {
  .cardItem-card {
    padding: 10px;
  }
  .top {
    text-align: center;
  }
  .el-input {
    width: 300px;
  }
}
</style>
